//
//  ClassifyRankContentView.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/9/7.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class ClassifyRankContentView: UIView {

    var backSeleIndex:BackSeleIndexValue!
    
    var bgView:UIView!
    
    lazy var filterView:ClassifyRankView = {
        let view = Bundle.main.loadNibNamed("ClassifyRankView", owner: nil, options: nil)?.first as! ClassifyRankView
        view.layer.masksToBounds = true
        view.setCornerRadio(radio: 20, isMask: true)
        view.frame = CGRect.init(x: UIScreen.ScreenWidth * 0.5, y: 85 + (Utils.isIphoneX() ? 88 : 64), width: UIScreen.ScreenWidth * 0.5, height: 0)
        view.backSeleIndex = {[weak self] (index) in
            if self?.backSeleIndex != nil {
                self?.backSeleIndex(index)
            }
            self?.hiden()
        }
        return view
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        self.isHidden = true
        bgView  = UIView.init(frame: CGRect.init(x: UIScreen.ScreenWidth * 0.5, y: 85 + (Utils.isIphoneX() ? 88 : 64), width: UIScreen.ScreenWidth * 0.5, height: 0))
        bgView.backgroundColor = UIColor.white
        bgView.setCornerRadio(radio: 20, isMask: false)
        bgView.setShadow(color: "000000", offset: CGSize.init(width: 0, height: 5), radius: 20, opacity: 0.1)
        self.addSubview(bgView)
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(hiden))
        self.addGestureRecognizer(tap)
        self.addSubview(filterView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func show(){
        self.isHidden = false
        UIView.animate(withDuration: 0.2) {
            self.bgView.height = 163
            self.filterView.height = 163
        }
    }
    
    @objc func hiden(){
        UIView.animate(withDuration: 0.2, animations: {
            self.bgView.height = 0
            self.filterView.height = 0
        }) { (_) in
            self.isHidden = true
        }
    }
    
    
}









